#ifndef _PRINT_H
#define _PRINT_H

#include <cstdint>
#include <cstddef>
#include <cstdio>
#include <string>

#ifdef __cplusplus
extern "C" {
#endif

class Print {
public:
    virtual size_t write(uint8_t c) = 0; // 纯虚函数，子类必须实现
    virtual size_t write(const uint8_t *buffer, size_t size);

    // 核心打印方法
    size_t print(const std::string &s);
    size_t print(char c);
    size_t print(int16_t num, int16_t base = 10);
    size_t print(uint16_t num, int16_t base = 10);
    size_t print(int32_t num, int16_t base = 10);
    size_t print(uint32_t num, int16_t base = 10);
    size_t print(double num, int16_t precision = 2);

    // 换行打印
    size_t println(const std::string &s);
    size_t println(char c);
    size_t println(int16_t num, int16_t base = 10);
    size_t println(uint16_t num, int16_t base = 10);
    size_t println(int32_t num, int16_t base = 10);
    size_t println(uint32_t num, int16_t base = 10);
    size_t println(double num, int16_t precision = 2);
    size_t println();

protected:
    size_t printNumber(uint32_t num, uint8_t base);
    size_t printFloat(double num, uint8_t precision);
};

#ifdef __cplusplus
}
#endif

#endif